package com.bb.Controllers;



import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.struts2.ServletActionContext;

import com.bb.pojo.House;
import com.bb.services.impl.HouseServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

public class HouseAction extends ActionSupport{
	private House house;//接收House的属性信息
	//使用属性接收数据开始
	private String h_style;//出租方式
	private String h_plot;//小区名
	private String h_rooms;//
	private String h_ting;//
	private String h_wei;//
	private String h_area;//
	private String h_floor;//
	private String h_total_floor;//
	private String h_money;//
	private String h_styly_money;//
	private String h_title;//
	private String h_desc;//
	private String h_person;//
	private String h_shenfen;//
	private String h_phone;//
	private File h_pic;//
	private String h_picFileName;//
	private String h_picContentType;//
	//使用属性接收数据结束
	//ajax提交返回布尔值
	private boolean boo;
	//ajax返回房屋的数据
	private Map dataMap;
	private String currentPage;//获取的当前页
	public String getCurrentPageHouse(){
		if(currentPage == null){
		 		currentPage = "1";
		 System.out.println(currentPage);
		 }
		 Map<String,Integer> map = new HashMap();
		 map.put("currentPage", Integer.parseInt(currentPage));
		 System.out.println(map);
		 HouseServiceImpl houseServiceImpl = new HouseServiceImpl();
		 dataMap= houseServiceImpl.selectHouse(map);
		 return "getallhouse";
	}
	//新增租房信息
	public String getAddHouse() throws FileNotFoundException, IOException{
		System.out.println("进入新增租房action");
		
		//把接收的数据,存到对象中
		house = new House();
		house.setH_style(Integer.parseInt(h_style));
		house.setH_plot(Integer.parseInt(h_plot));
		house.setH_rooms(Integer.parseInt(h_rooms));
		house.setH_ting(Integer.parseInt(h_ting));
		house.setH_wei(Integer.parseInt(h_wei));
		house.setH_area(Integer.parseInt(h_area));
		house.setH_floor(Integer.parseInt(h_floor));
		house.setH_total_floor(Integer.parseInt(h_total_floor));
		house.setH_money(Integer.parseInt(h_money));
		house.setH_styly_money(Integer.parseInt(h_styly_money));
		house.setH_title(h_title);
		house.setH_desc(h_desc);
		house.setH_person(h_person);
		house.setH_shenfen(Integer.parseInt(h_shenfen));
		house.setH_phone(h_phone);
		house.setH_pic(h_picFileName);
		System.out.println(house);
		//上传那图片
		if(h_pic != null){
			String realPath = ServletActionContext.getServletContext().getRealPath("upload");
			String path = realPath + File.separator + h_picFileName;
			IOUtils.copy(new FileInputStream(h_pic), new FileOutputStream(path));
		}
		System.out.println(house);
		System.out.println(h_pic);
		System.out.println(h_picFileName);
		
		int addHouse = new HouseServiceImpl().addHouse(house);
		
		if(addHouse>0){
			boo=true;
			System.out.println("添加成功！！！");
		}
		
		
		return "addHouseSuccess";
	}
	//进入租房的页面
	public String insertintoHouse(){
		return "insertSuccess";
	}
	
	
	
	
	public House getHouse() {
		return house;
	}

	public void setHouse(House house) {
		this.house = house;
	}
	public String getH_style() {
		return h_style;
	}
	public void setH_style(String h_style) {
		this.h_style = h_style;
	}
	public String getH_plot() {
		return h_plot;
	}
	public void setH_plot(String h_plot) {
		this.h_plot = h_plot;
	}
	public String getH_rooms() {
		return h_rooms;
	}
	public void setH_rooms(String h_rooms) {
		this.h_rooms = h_rooms;
	}
	public String getH_ting() {
		return h_ting;
	}
	public void setH_ting(String h_ting) {
		this.h_ting = h_ting;
	}
	public String getH_wei() {
		return h_wei;
	}
	public void setH_wei(String h_wei) {
		this.h_wei = h_wei;
	}
	public String getH_area() {
		return h_area;
	}
	public void setH_area(String h_area) {
		this.h_area = h_area;
	}
	public String getH_floor() {
		return h_floor;
	}
	public void setH_floor(String h_floor) {
		this.h_floor = h_floor;
	}
	
	public String getH_total_floor() {
		return h_total_floor;
	}
	public void setH_total_floor(String h_total_floor) {
		this.h_total_floor = h_total_floor;
	}
	public String getH_money() {
		return h_money;
	}
	public void setH_money(String h_money) {
		this.h_money = h_money;
	}
	public String getH_styly_money() {
		return h_styly_money;
	}
	public void setH_styly_money(String h_styly_money) {
		this.h_styly_money = h_styly_money;
	}
	public String getH_title() {
		return h_title;
	}
	public void setH_title(String h_title) {
		this.h_title = h_title;
	}
	public String getH_desc() {
		return h_desc;
	}
	public void setH_desc(String h_desc) {
		this.h_desc = h_desc;
	}
	public String getH_person() {
		return h_person;
	}
	public void setH_person(String h_person) {
		this.h_person = h_person;
	}
	public String getH_shenfen() {
		return h_shenfen;
	}
	public void setH_shenfen(String h_shenfen) {
		this.h_shenfen = h_shenfen;
	}
	public String getH_phone() {
		return h_phone;
	}
	public void setH_phone(String h_phone) {
		this.h_phone = h_phone;
	}
	public File getH_pic() {
		return h_pic;
	}
	public void setH_pic(File h_pic) {
		this.h_pic = h_pic;
	}
	public String getH_picFileName() {
		return h_picFileName;
	}
	public void setH_picFileName(String h_picFileName) {
		this.h_picFileName = h_picFileName;
	}
	public String getH_picContentType() {
		return h_picContentType;
	}
	public void setH_picContentType(String h_picContentType) {
		this.h_picContentType = h_picContentType;
	}
	public boolean isBoo() {
		return boo;
	}
	public void setBoo(boolean boo) {
		this.boo = boo;
	}
	public Map getDataMap() {
		return dataMap;
	}
	public void setDataMap(Map dataMap) {
		this.dataMap = dataMap;
	}
	public String getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}

	
	
	
	//包含的有图片
	
}
